<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<script type="text/javascript">

    function object(O) {
        function Fun() {}
        // 将传入的对象做为Fun的原型
        Fun.prototype = O
        return new Fun()
    }
    var person = {
        name: '喜羊羊',
        friends: ['懒羊羊', '美羊羊']
    }
    var anotherPerson = object(person)
    console.log(anotherPerson)
    anotherPerson.name = '沸羊羊'
    // friends来自于临时的Fun的原型中，每次添加会添加到它的原型中
    // Fun的原型是传入的person
    anotherPerson.friends.push('暖羊羊')
    var yetAnotherPerson = object(person)
    yetAnotherPerson.name = '沸羊羊'
    yetAnotherPerson.friends.push('暖羊羊')
    console.log(person.friends)

</script>

</body>
</html>
